<header class="ui basic very padded segment dream-header">
  {{ if isset .Site.Params "avatar" }}
  <div class="ui small circular image">
    <img src="{{ .Site.Params.avatar | relURL }}" alt="avatar" />
  </div>
  {{ end }}

  <div class="content">
    <h1 class="ui medium header">
      {{- if .Site.Params.headerTitle -}}
        {{- .Site.Params.headerTitle -}}
      {{- else -}}
        Set headerTitle in the config to display
      {{- end -}}
      <span class="sub header">
        {{- .Site.Params.motto | safeHTML -}}
      </span>
    </h1>

    <article class="ui horizontal list">
      {{ if gt (len (where .Site.RegularPages "Section" "==" "posts")) 0 }}
      <a class="item" href="{{ "posts" | relLangURL }}">
        <i class="archive icon" title="{{ T "archives" }}"></i>
      </a>
      {{ end }}
      <a class="item" href="{{ "categories" | relLangURL }}">
        <i class="th list icon" title="{{ T "allCategories" }}"></i>
      </a>
      <a class="item" href="{{ "tags" | relLangURL }}">
        <i class="tags icon" title="{{ T "allTags" }}"></i>
      </a>
    </article>

    {{ if .Site.Taxonomies.tags }}
    {{ $tags := slice }}
    {{ $first := slice }}
    {{ $rest := slice }}
    {{ range .Site.Taxonomies.tags }}
      {{ $tags = $tags | append (dict "title" .Page.Title "link" .Page.RelPermalink) }}
    {{ end }}
    {{ $sum := len $tags }}

    {{ $maxTags := .Site.Params.maxTags }}

    {{ if $maxTags }}

    {{ $first = first $maxTags $tags }}
    {{ $rest = last (sub $sum $maxTags) $tags }}

    <div class="tags-with-dropdown">
      <div class="ui accordion">
        <div class="title">
          <div class="ui horizontal list">
            <a class="item dropdown" href="#">
              <i class="chevron right icon dropdown-icon"></i>
            </a>
          </div>
          <div class="dream-tags">
          {{ range $tag := $first }}
          {{ $title := index $tag "title" }}
          {{ $link := index $tag "link" }}
            <a class="ui label" href="{{ $link }}" title="{{ $title }}">
              {{ $title }}
            </a>
          {{ end }}
          </div>
        </div>
        <div class="content">
    {{ else }}
    {{ $rest = $tags }}
    {{ end }}
          <div class="dream-tags"{{ if $maxTags }} style="margin-left: 1.5rem;"{{ end}}>
          {{ range $tag := $rest }}
          {{ $title := index $tag "title" }}
          {{ $link := index $tag "link" }}
            <a class="ui label" href="{{ $link }}" title="{{ $title }}">
              {{ $title }}
            </a>
          {{ end }}
          </div>
    {{ if $maxTags }}
        </div>
      </div>
    </div>
    {{ end }}

    {{ end }}
  </div>
</header>
